<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <template slot="footer">
      <a-button @click="close">取消</a-button>
      <a-button v-if="title=='审批'" :loading="confirmLoading" type="primary" @click="handleadd('50')">通过</a-button>
      <a-button v-if="title=='审批'" :loading="confirmLoading" type="primary" @click="handleadd('70')">驳回</a-button>
      <a-button v-if="!disableSubmit" :loading="confirmLoading" type="primary" @click="handleOk('zc')">暂存</a-button>
      <a-button v-if="!disableSubmit" :loading="confirmLoading" type="primary" @click="handleOk('tj')">提交</a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-divider orientation="left">基础信息</a-divider>
          <a-col :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="客户编号"
            >
              <a-input-search :disabled="disableSubmit||model.orderType=='ZO10'" v-decorator="['custCode',validatorRules.custCode]"
                              placeholder="请选择"
                              readOnly enter-button @search="custSearch('custCode')"/>
              <a-input type="hidden" :disabled="true" v-decorator="['custCode']"/>

            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="客户名称"
            >
              <a-input placeholder="请输入" :disabled="true" v-decorator="['custName']"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="物流模式"
            >
              <a-select
                :disabled="disableSubmit||model.orderType=='ZO10'"
                v-decorator="['logisticsPatternCode',{ initialValue:'1' }]"
                placeholder="速冻"
                @change="updateHead"
              >
                <a-select-option value="1">
                  速冻
                </a-select-option>
                <a-select-option value="2">
                  常温
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="收货地址"
            >
              <a-input-search :disabled="disableSubmit" v-decorator="['addressDetailed',validatorRules.addressDetailed]"
                              placeholder="请选择收货地址"
                              readOnly enter-button @search="custSearch0('addressCode')"/>
              <a-input type="hidden" v-decorator="['addressCode']"/>
              <a-input type="hidden" v-decorator="['addressRegion']"/>
              <a-input type="hidden" v-decorator="['consignee']"/>
              <a-input type="hidden" v-decorator="['consigneeCall']"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="提货方式"
            >
              <a-select
                :disabled="disableSubmit||model.orderType=='ZO10'"
                v-decorator="['deliveryMethod',{initialValue:'ps'}]"
                placeholder="配送"
                @change="updateHead"
              >
                <a-select-option value="ps">
                  配送
                </a-select-option>
                <a-select-option value="zt">
                  自提
                </a-select-option>
              </a-select>
              <!--              <a-input placeholder='请输入' v-decorator="[ 'yw', validatorRules.address]" />-->
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="提货点"
            >
              <a-select :disabled="disableSubmit||model.orderType=='ZO10'" v-decorator="['pupCode']" placeholder="提货点"
                        @change="handleSelectPick">
                <a-select-option v-for="(item,index) in pupList" :key="index" :name="item.name"
                                 :value="item.code">
                  {{ item.name }}
                </a-select-option>
              </a-select>
              <a-input type="hidden" v-decorator="['pupName']"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="是否拼车"
            >
              <a-select
                v-if="title !== '详情'"
                :disabled="disableSubmit||model.orderType=='ZO10'"
                v-decorator="['isCarpooling',{initialValue:'N'}]"
                placeholder="拼车">
                <a-select-option value="N">
                  否
                </a-select-option>
                <a-select-option value="W">
                  发起拼车
                </a-select-option>
                <a-select-option value="L">
                  参与拼车
                </a-select-option>
              </a-select>
              <a-input v-else :disabled="true" v-decorator="['isCarpoolingDesc']"></a-input>
              <a-input type="hidden" :disabled="true" v-decorator="['carpoolingCode']"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" v-if="form.getFieldValue('isCarpooling')=='L'">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="拼车单号:"
            >
              <a-input :disabled="disableSubmit||model.orderType=='ZO10'" placeholder="请输入拼车单号" v-decorator="['carpoolingCode']"
                       @blur="updateHead"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" v-if="form.getFieldValue('cooperationWayCode') == '8'">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="最终团购客户:"
            >
              <a-input-search :disabled="disableSubmit||model.orderType=='ZO10'" v-decorator="['gpCustName',validatorRules.customerCode]"
                              placeholder="请选择"
                              readOnly enter-button @search="gpCustSearch('gpCustCode')"/>
              <a-input type="hidden" :disabled="true" v-decorator="['gpCustCode']"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" v-if="form.getFieldValue('cooperationWayCode') == '7'">
            <a-form-item label="出口定价日期:" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-date-picker :disabled="disableSubmit||model.orderType=='ZO10'" format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                             v-decorator="['exportPricingDate']"
                             @change="updateHead"
                             style="width:100%"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="原始单据号:">
              <a-input :disabled="disableSubmit||model.orderType=='ZO10'" placeholder="请输入" v-decorator="['originalCode']"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" v-if="payerList.length||(disableSubmit&&model.invoiceTypeDesc)">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="发票类型"
            >
              <a-select v-if="!disableSubmit" :disabled="disableSubmit||model.orderType=='ZO10'" v-decorator="['invoiceType']" placeholder="发票类型"
                        @change="handleSelectPay">
                <a-select-option v-for="(item,index) in payerList" :key="index" :name="item.invoiceTypeDesc"
                                 :payerCode="item.payerCode"
                                 :value="item.invoiceType">
                  {{ item.invoiceTypeDesc }}
                </a-select-option>
              </a-select>
              <a-input v-else type="text" :disabled="disableSubmit" v-decorator="['invoiceTypeDesc']"/>
              <a-input type="hidden" v-decorator="['payerCode']"/>
            </a-form-item>
          </a-col>
          <!--          ZO16 ZO11-->
          <span v-if="['ZO16', 'ZO11'].includes(model.orderType)">
            <a-col :md="8" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="卖场名称:">
                <a-input :disabled="true" :value="model.salestoresDesc"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="下单时间:">
                <a-input :disabled="true" :value="model.originalOrderdate"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="订单有效期:">
                <a-input :disabled="true" :value="model.originalDbilldate"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
                label="价格状态:">
                <a-input :disabled="true" :value="model.priceStatus==1?'正常':'异常'"/>
              </a-form-item>
            </a-col>
          </span>
        </a-row>
      </a-form>

      <!-- 活动明细 -->
      <a-divider orientation="left">产品信息</a-divider>
      <div style="margin-bottom: 10px;display: flex;">
        <cn-select-goods selectButtonText="添加产品"
                         name="商品"
                         :inputs="false"
                         :queryParams="{customerCode: form.getFieldValue('custCode')}"
                         :buttons="true"
                         :multiple="true"
                         rowKey="goodsCode"
                         :queryConfig="queryConfig"
                         :returnName="true"
                         listUrl="/goods/cnGoods/findPcPageEnoughList"
                         :disabled="disableSubmit||!form.getFieldValue('custCode')"
                         @select="selectGoodsBp"
                         class="form-input">
        </cn-select-goods>
        <a-button style="margin: 0 0px 0px 15px;" :disabled="disableSubmit||!form.getFieldValue('custCode')"
                  @click="custSearch1('superiorUser')" type="primary">添加货补
        </a-button>
        <!--      <a-button style="margin: 0 0px 0px 5px;" @click="custSearch2('superiorUser')" type="primary">添加赠品</a-button>-->
        <a-button style="margin: 0px 0px 0px 5px;" :disabled="disableSubmit||!form.getFieldValue('custCode')"
                  @click="handleAdd1" type="primary">收藏商品
        </a-button>
        <a-upload
          :file-list="dataGrid.fileList"
          :remove="handleRemove"
          :before-upload="beforeUpload"
          :disabled="disableSubmit||!form.getFieldValue('custCode')"
          accept=".xlsx,.xls">
          <a-button style="margin: 0px 0px 0px 5px;" :disabled="disableSubmit||!form.getFieldValue('custCode')">
            导入商品
          </a-button>
        </a-upload>
        <a-button style="margin: 0px 0px 0px 5px;"
                  @click="handleExportXls('商品行导入模版')" type="primary">模版下载

        </a-button>
        <!--        <a-button style="margin: 0px 0px 0px 5px;" @click="handleAdd2" type="primary">常购清单</a-button>-->
      </div>

      <div style="margin-bottom: 20px">
        <div class="table-box pt10">
          <div class="table-head-box">
            <div class="table-head-th td-spbm" v-if="['ZO16', 'ZO11'].includes(model.orderType)"> 条形码</div>
            <div class="table-head-th td-spbm"> 商品编号</div>
            <div class="table-head-th td-spmc"> 商品名称</div>
            <div class="table-head-th td-hlx"> 行类型</div>
            <div class="table-head-th td-dw"> 单位</div>
            <div class="table-head-th td-kc" v-if="!disableSubmit&&form.getFieldValue('cooperationWayCode')!=2"> 库存
            </div>
            <div class="table-head-th td-dj" v-if="['ZO16', 'ZO11'].includes(model.orderType)"> KA价</div>
            <div class="table-head-th td-dj"> 单价</div>
            <div class="table-head-th td-jsj"> 结算价</div>
            <div class="table-head-th td-jsj" v-if="['ZO16', 'ZO11'].includes(model.orderType)">
              价格状态
            </div>
            <div class="table-head-th td-ysds" v-if="['ZO16', 'ZO11'].includes(model.orderType)"> 原订单数</div>
            <div class="table-head-th td-sl" v-if="!disableSubmit"> 最小托盘量</div>
            <div class="table-head-th td-sl"> 数量</div>
            <div class="table-head-th td-sl"> 建议数量</div>
            <div class="table-head-th td-jsje"> 总金额</div>
            <div class="table-head-th td-zc" v-if="model.orderType!='ZO16'&& model.orderType!='ZO11'"> 政策</div>
            <div class="table-head-th td-fhsl" v-if="model.orderStatus=='60'"> 发货数量</div>
            <div class="table-head-th td-shsl" v-if="model.orderStatus=='60'"> 收货数量</div>
            <div class="table-head-th td-shsl" v-if="model.orderStatus=='60'"> 签收备注</div>
            <div class="table-head-th td-cz"> 操作</div>
          </div>
          <div v-for="(items,indexs) in dataList" :key="index">
            <div class="table-body-box " v-for="(bpItem,bpIndex) in items.shoppingHeads" :key="bpIndex">
              <div class="table-body-td td-spbm" v-if="['ZO16', 'ZO11'].includes(model.orderType)">
                {{ bpItem.barCode }}
              </div>
              <div class="table-body-td td-spbm">
                {{ bpItem.productCode.length == 18 ? (bpItem.productCode.substr(10, 10)) : bpItem.productCode }}
              </div>
              <div class="table-body-td td-spmc"> {{ bpItem.goodsName }}</div>
              <div class="table-body-td td-hlx">
                <a-tag color="blue">
                  {{ bpItem.dataTypeDes }}
                </a-tag>
                <a-tag color="red" v-if="bpItem.drqType=='F'">
                  大日期
                </a-tag>
              </div>
              <div class="table-body-td td-dw">{{ bpItem.unitDesc }}</div>
              <div class="table-body-td td-kc" v-if="!disableSubmit&&form.getFieldValue('cooperationWayCode')!=2">
                {{ bpItem.stock }}
              </div>
              <div class="table-body-td td-dj" v-if="['ZO16', 'ZO11'].includes(model.orderType)">
                {{ bpItem.originalPiecePrice }}
              </div>
              <div class="table-body-td td-dj"> {{ bpItem.originalPrice }}</div>
              <div class="table-body-td td-jsj"> {{ bpItem.payPrice }}</div>
              <div class="table-body-td td-jsj" v-if="['ZO16', 'ZO11'].includes(model.orderType)">
                <a-tag color="#108ee9" v-if="bpItem.priceStatus==1">
                  正常
                </a-tag>
                <a-tag color="#f50" v-else>
                  异常
                </a-tag>
              </div>
              <div class="table-body-td td-ysds" v-if="['ZO16', 'ZO11'].includes(model.orderType)"> {{
                  bpItem.kaNnumber
                }}
              </div>
              <div class="table-body-td td-sl" v-if="!disableSubmit"> {{ bpItem.wholeTrayStandard }}</div>
              <div class="table-body-td td-sl">
                <a-input-number
                  :disabled="disableSubmit || (bpItem.dataType==3&&!['3','4','5'].includes(form.getFieldValue('cooperationWayCode'))) || bpItem.drqType=='F'"
                  id="inputNumber"
                  v-model="bpItem.quantity"
                  :min="['ZO16', 'ZO11'].includes(model.orderType)?0:1"
                  :max="99999"
                  @blur="upDataCart(bpItem)"
                  style="width: 80px !important;"/>
              </div>
              <div class="table-body-td td-sl" > {{bpItem.recommendedQuantity}}</div>
              <div class="table-body-td td-jsje"> {{ bpItem.subTotal }}</div>
              <div class="table-body-td td-zc" v-if="model.orderType!='ZO16'&& model.orderType!='ZO11'">
                <a-select v-if="bpItem.promotionVos&&bpItem.promotionVos.length" v-model="bpItem.promotionCode"
                          :disabled="disableSubmit"
                          placeholder="请选择" style="width: 170px"
                          @change="upDataCart(bpItem,'promotion')">
                  <a-select-option v-for="(ptItem,index) in bpItem.promotionVos" :key="index" :name="ptItem.pmName"
                                   :value="ptItem.pmCode">
                    <template>
                      <a-tooltip>
                        <template slot="title">
                          {{ ptItem.pmName }}
                        </template>
                        {{ ptItem.pmName }}
                      </a-tooltip>
                    </template>
                  </a-select-option>
                </a-select>
                <span v-if="disableSubmit"> {{ bpItem.promotionName || '' }} </span>
              </div>
              <div class="table-body-td td-fhsl" v-if="model.orderStatus=='60'"> {{ bpItem.deliverNum || 0 }}</div>
              <div class="table-body-td td-shsl" v-if="model.orderStatus=='60'"> {{ bpItem.signForNum || 0 }}</div>
              <div class="table-body-td td-shsl" v-if="model.orderStatus=='60'"> {{ bpItem.remarks }}</div>
              <div class="table-body-td td-cz">
                <div @click.stop.prevent style="width: 100%;height: 100%;text-align: center"
                     v-if="bpItem.drqType!='F'&&bpItem.dataType!=3">
                  <a-button :disabled="disableSubmit" @click="deleteRow(bpItem.id)" type="text" size="small">删除
                  </a-button>
                </div>
              </div>
            </div>
            <div class="table-body-box-zp" v-if="items.shoppingHeadZps||items.gitGoodsLis">
              <template v-for="(zpItem,zpIndex) in items.shoppingHeadZps.concat(items.gitGoodsLis)">
                <div class="table-body-box  bg-ebebeb" v-if="zpIndex <3|| items.show">
                  <div class="table-body-td td-spbm" v-if="['ZO16', 'ZO11'].includes(model.orderType)">
                    {{ bpItem.barCode }}
                  </div>
                  <div class="table-body-td td-spbm">
                    {{ zpItem.productCode.length == 18 ? (zpItem.productCode.substr(10, 10)) : zpItem.productCode }}
                  </div>
                  <div class="table-body-td td-spmc"> {{ zpItem.goodsName }}</div>
                  <div class="table-body-td td-hlx">
                    <a-tag color="#f50">
                      赠品
                    </a-tag>
                  </div>
                  <div class="table-body-td td-dw"> {{ zpItem.unitDesc }}</div>
                  <div class="table-body-td td-kc" v-if="!disableSubmit&&form.getFieldValue('cooperationWayCode')!=2">
                    {{ zpItem.stock }}
                  </div>
                  <div class="table-body-td td-dj" v-if="['ZO16', 'ZO11'].includes(model.orderType)">
                    {{ zpItem.originalPiecePrice }}
                  </div>
                  <div class="table-body-td td-dj"> {{ zpItem.originalPrice }}</div>
                  <div class="table-body-td td-jsj"> {{ zpItem.payPrice }}</div>
                  <div class="table-body-td td-jsj" v-if="['ZO16', 'ZO11'].includes(model.orderType)">
                    <a-tag color="#108ee9" v-if="bpItem.priceStatus==1">
                      正常
                    </a-tag>
                    <a-tag color="#f50" v-else>
                      异常
                    </a-tag>
                  </div>
                  <div class="table-body-td td-ysds" v-if="['ZO16', 'ZO11'].includes(model.orderType)">
                    {{ zpItem.kaNnumber }}
                  </div>
                  <div class="table-body-td td-sl" v-if="!disableSubmit"></div>
                  <div class="table-body-td td-sl">
<!--                    <a-input-number :disabled="disableSubmit" size="mini" @blur="addPmZps(items,$event)"-->
<!--                                    v-model="zpItem.quantity"-->
<!--                                    :min="0"></a-input-number>-->
                    {{zpItem.quantity}}
                  </div>
                  <template v-if="title=='详情'">
                    <div class="table-body-td td-sl" > {{zpItem.recommendedQuantity}}</div>
                    <div class="table-body-td td-jsje">{{ zpItem.subTotal }}</div>
                    <div class="table-body-td td-zc" v-if="model.orderType!='ZO16'&& model.orderType!='ZO11'"></div>
                    <div class="table-body-td td-fhsl" v-if="model.orderStatus=='60'"> {{
                        zpItem.deliverNum || 0
                      }}
                    </div>
                    <div class="table-body-td td-shsl" v-if="model.orderStatus=='60'"> {{
                        zpItem.signForNum || 0
                      }}
                    </div>
                    <div class="table-body-td td-shsl" v-if="model.orderStatus=='60'"> {{ zpItem.remarks }}</div>
                    <div class="table-body-td td-cz">
                    </div>
                  </template>
                  <template v-if="title!='详情'">
                    <div class="table-body-td td-zl" v-if="zpIndex===0">
                      赠品总量: {{ rowNum(items.shoppingHeadZps) }}
                    </div>
                    <div class="table-body-td td-zpkxsl"
                         v-if="(items.gitTotal - rowNum(items.shoppingHeadZps))>=0&&zpIndex===0">
                      剩余数：{{ items.gitTotal - rowNum(items.shoppingHeadZps) }}
                    </div>
                    <div class="table-body-td td-zpkxsl"
                         v-else-if="(items.gitTotal - rowNum(items.shoppingHeadZps))<0&&zpIndex===0">
                      超出可选范围({{ items.gitTotal }})
                    </div>
                  </template>
                </div>
              </template>
            </div>
            <div class="font14 p5" style="text-align: center;"
                 v-if="(items.shoppingHeadZps.concat(items.gitGoodsLis))&&(items.shoppingHeadZps.concat(items.gitGoodsLis)).length>3&&!items.show"
                 @click="items.show = true">
              <a-icon type="double-left" class="arrow-down"/>
              点击加载更多商品
            </div>
            <div class="font14 p5" style="text-align: center;"
                 v-if="(items.shoppingHeadZps.concat(items.gitGoodsLis))&&items.shoppingHeadZps.concat(items.gitGoodsLis).length>3&&items.show"
                 @click="items.show = false">
              <a-icon type="double-left" class="arrow-up"/>
              点击收起更多商品
            </div>
          </div>
        </div>
      </div>

      <a-divider orientation="left">结算信息</a-divider>
      <div style="height: 130px;background-color: #F2F2F2">
        <div style="display: flex;padding: 10px 10px 0px 20px">
          <div style="flex: 1">原价金额:{{ bottomInfo.originalPriceTotal || 0 }}元</div>
          <div style="flex: 1">优惠金额:{{ bottomInfo.preferentialAmount || 0 }}元</div>
          <div style="flex: 1.2">结算金额:{{ bottomInfo.totalPayAmount || 0 }}元</div>
<!--          <div style="flex: 1.5" v-if="!disableSubmit&&form.getFieldValue('deliveryMethod')!=='zt'">-->
<!--            匹配车型:{{ model.matchingModelsMsg || '-' }}-->
<!--          </div>-->
<!--          <div style="flex: 1.5" v-else>{{ model.optimumMatchModel || '-' }}</div>-->
<!--          <div style="flex: 1">-->
<!--            <a-button type="primary" @click="showModal">配车参考</a-button>-->
<!--            <a-modal v-model:visible="visible1" title="配车参考" @ok="handleOk1">-->
<!--              <a-table-->
<!--                ref="table"-->
<!--                size="middle"-->
<!--                bordered-->
<!--                rowKey="id"-->
<!--                :columns="columns1"-->
<!--                :dataSource="dataSource1"-->
<!--                :pagination="false"-->
<!--                :confirmLoading="confirmLoading"-->
<!--                class="Table j-table-force-nowrap"-->
<!--              >-->
<!--              </a-table>-->
<!--            </a-modal>-->
<!--          </div>-->
        </div>
        <div style="display: flex;padding: 5px 10px 5px 20px">
          <div style="flex: 1">订单件数:{{ bottomInfo.totalQuantity || 0 }}件</div>
          <div style="flex: 1">折合件数:{{ bottomInfo.totalConvertNumber || 0 }}</div>
          <div style="flex: 2.2" v-if="!disableSubmit">可用余额(不含本单): {{ balance|moneyTwoPoint }}元</div>
          <div style="flex: 2.2" v-else></div>
          <!--        还需打款:-->
          <div style="flex: 1.5"></div>
        </div>
        <div>
          <a-form :form="form">
            <a-col :md="24" :sm="24">
              <a-form-item
                :labelCol="{ xs: { span:10 }, sm: { span: 1}}"
                :wrapperCol="{ xs: { span:10 }, sm: { span: 22}}"
                label="备注"
                style="margin-left: 10px"
              >
                <a-textarea :disabled="disableSubmit" placeholder="尊敬的客户，因车型差异，装车时可能存在溢车的情况，请备注最后装车商品"
                            v-decorator="['remarks', ]"/>
                <!--              <a-input placeholder='请输入' v-decorator="[ 'yw', validatorRules.address]" />-->
              </a-form-item>
            </a-col>
          </a-form>
        </div>
      </div>
    </a-spin>
    <!--    选择产品-->
    <my-shuttle-modal
      ref="shuttleModal"
      :createdShow="false"
      :title="modelname"
      :searchConfig="searclist"
      :columns="columnsModal"
      :columns2="columnsModal2"
      :leftUrl="url.goodsList"
      @chooseOk="selectGoodsBp"
    ></my-shuttle-modal>
    <proChose :name="modelname" ref="prochoose" v-bind="modalProps" @okbro="okbropro"></proChose>
    <orderspModal :name="modelname" ref="orderspModal" v-bind="modalProps" @ok="updateHB"></orderspModal>
  </j-modal>
</template>

<script>
import JTreeSelect from '@/components/cn-form/JTreeSelect'
import orderspModal from './orderspModal.vue'
import { downFile, getAction, httpAction, postAction } from '@/api/manage'
import pick from 'lodash.pick'
import moment from 'moment'
import proChose from '@comp/cn-components/ProChose'
import CnMultiSelectTag from '@/components/dict/CnMultiSelectTag'
import myShuttleModal from '@/components/cn-components/CnShuttleModal'
import { PageListMixin } from '@/mixins/PageListMixin'
import JSelectProduct from '@/components/cn-select-popup/JSelectProduct'
import JSelectCust from '@comp/cn-select-popup/CnSelectCust'
import CnSelectGoods from '@comp/cn-select-popup/CnSelectGoods'
import CodeConfigModal from '@/components/cn-select-popup/CodeConfigModal'
import XLSX from 'xlsx'

export default {
  name: 'TpmActSpecialModal',
  components: {
    CnSelectGoods,
    JTreeSelect,
    CnMultiSelectTag,
    JSelectProduct,
    CodeConfigModal,
    JSelectCust,
    proChose,
    myShuttleModal,
    orderspModal
  },
  mixins: [PageListMixin],
  data() {
    return {
      title: '操作',
      visible: false,
      visible1: false,
      disableSubmit: false,
      id:'',
      model: {},
      modelname: '关联',
      searclist: [],
      columnslist: [],
      columnslist2: [],
      tempUuid: '',
      showterm: false,
      showorg: false,
      balance: 0,
      queryConfig: [{
        label: '商品名称',
        key: 'goodsName'
      }, {
        label: '69码',
        key: 'barCode'
      },],
      tableData: [
        {
          productList: [{}, {}],
          giftLsit: [{}, {}, {}, {}, {}],
          show: false,
        },
        {
          productList: [{}, {}],
          giftLsit: [{}, {}, {}, {}, {}],
          show: false,
        }
      ],
      columns1: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '车型',
          align: 'center',
          dataIndex: 'cx'
        },
        {
          title: '有效利用体积（立方米）',
          align: 'center',
          dataIndex: 'tj'
        },
        {
          title: '折合件数区间（件）',
          align: 'center',
          dataIndex: 'qj'
        },
      ],
      dataSource1: [
        {
          cx: '4.2米',
          tj: '5-14',
          qj: '200-550'
        },
        {
          cx: '6.8米米',
          tj: '19-23',
          qj: '750-900'
        },
        {
          cx: '7.2米',
          tj: '20-33',
          qj: '800-1300'
        },
        {
          cx: '8.6米',
          tj: '32.5-36.4',
          qj: '1250-1400'
        },
        {
          cx: '9.6米',
          tj: '39-42.9',
          qj: '1500-1650'
        },
        {
          cx: '13.7米',
          tj: '52-59.8',
          qj: '2000-2300'
        }
        , {
          cx: '15米',
          tj: '57.2-70.2',
          qj: '2200-2700'
        }
      ],
      dataGrid: {},
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key: 'rowIndex',
        //   width: 60,
        //   align: 'center',
        //   customRender: function(t, r, index) {
        //     return parseInt(index) + 1
        //   }
        // },
        {
          title: '行号',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '类型',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '产品编号',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '产品名称',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '整托标准',
          align: 'center',
          dataIndex: '',
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: '',
        },
        {
          title: '原始订单袋数',
          align: 'center',
          dataIndex: '',
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: '',
        },
        {
          title: '原价',
          align: 'center',
          dataIndex: '',
        },
        {
          title: '结算价',
          align: 'center',
          dataIndex: '',
        },
        {
          title: '小计',
          align: 'center',
          dataIndex: '',
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      searchConfig: [
        {
          type: 'input',
          name: 'goodsCode',
          placeholder: '产品编号',

        },
        {
          type: 'input',
          name: 'goodsName',
          placeholder: '产品名称',
        },

      ],
      columnsModal: [
        {
          title: '商品编号',
          align: 'center',
          dataIndex: 'productCode'
        },
        {
          title: '商品名称',
          align: 'center',
          dataIndex: 'productName'
        },
      ],
      columnsModal2: [
        {
          title: '产品编号',
          align: 'center',
          dataIndex: 'goodsCode'
        },
        {
          title: '产品名称',
          align: 'center',
          dataIndex: 'goodsName'
        },
        {
          title: '操作',
          dataIndex: 'action',
          // fixed: 'right',
          align: 'center',
          scopedSlots: {
            customRender: 'delete'
          }
        }
      ],
      searchConfig1: [
        {
          type: 'input',
          name: 'goodsCode',
          placeholder: '商品编号',

        },
        {
          type: 'input',
          name: 'goodsName',
          placeholder: '商品名称',
        },

      ],
      columnsModal1: [
        {
          title: '商品编号',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '商品名称',
          align: 'center',
          dataIndex: ''
        },
      ],
      columnsModal21: [
        {
          title: '商品编号',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '商品名称',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: 60,
          align: 'center',
          scopedSlots: {
            customRender: 'delete'
          }
        }
      ],
      searchConfig2: [
        {
          type: 'input',
          name: '',
          placeholder: '产品编号',

        },
        {
          type: 'input',
          name: '',
          placeholder: '产品名称',
        },

      ],
      columnsModal12: [
        {
          title: '产品编号',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '产品名称',
          align: 'center',
          dataIndex: ''
        },
      ],
      columnsModal22: [
        {
          title: '产品编号',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '产品名称',
          align: 'center',
          dataIndex: ''
        },
        {
          title: '操作',
          dataIndex: 'action',
          // fixed: 'right',
          align: 'center',
          scopedSlots: {
            customRender: 'delete'
          }
        }
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      tabs: {
        activeKey: 'global',
        global: {
          key: 'global',
          columns: [],
          dataSource: []
        }
      },
      payerList: [],
      dataSource: [],
      dataList: [], // 商品信息
      bottomInfo: {}, // 结算信息
      pupList: [], // 提货点
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        customerCode: { rules: [{ required: true, message: '' }] },
        select: { rules: [{ required: true, message: '' }] }
      },
      url: {
        add: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/submitOrder',
        addCart: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/addShopping',
        edit: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/submitZcOrder',
        payer: window._CONFIG['domianURL'] + '/customer/cnCustomerPayer/findCustomerCodeByPayerList',
        detail: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/findOrderInfo',
        editDetail: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/findOrderChangeInfo',
        updateInfo: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/findOrderChangeInfo',
        custInfo: window._CONFIG['domianURL'] + '/customer/cnCustomer/getInfo',
        custInfoByCode: window._CONFIG['domianURL'] + '/customerController/findByCustomerCode',
        addHead: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/upOrderByCust',
        adddata:window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/orderReview',
        addDZShopping: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/addDZShopping',
        shoppingUpQuantity: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/shoppingUpQuantity',
        delShopping: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/delShopping',
        goodsList: '/favorites/cnFavorites/findPageList',
        // match: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/findShoppingMatchingModels',
        pickspot: window._CONFIG['domianURL'] + '/customerController/findPickUpByCustCode',
        stock: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/findProductCodeListByStockList',
        addressUrl: window._CONFIG['domianURL'] + '/receivedgoodsaddress/cnReceivedGoodsAddress/findPageList',
        // 模版下载
        exportXlsUrl: window._CONFIG['domianDmsURL'] + '/order/dmsOrderHead/downloadTemplate',
      }
    }
  },
  created() {
  },
  computed: {
    modalProps() {
      return {
        name: this.name
      }
    },
    rowNum: () => {
      return function (row) {
        if (row) {
          return row.reduce((total, item) => total + (item.quantity || 0), 0)
        } else {
          return 0
        }
      }
    }
  },
  methods: {
    moment,
    // 提货点选择
    async handleSelectPick(e, v) {
      this.form.setFieldsValue({
        pupName: v.data.attrs.name
      })
      this.updateHead()
    },
    async handleSelectPay(e, v) {
      this.form.setFieldsValue({
        payerCode: v.data.attrs.payerCode
      })
      this.getBalance(this.form.getFieldValue('customerCode'))
    },

    chooseOk(e, list) {
      console.log(e, list)
    },
    async updateHead() {
      let info = await this.form.getFieldsValue()
      let params = {
        ...info,
        id: this.model.id
      }
      let res = await postAction(this.url.addHead, params)
      if (res.success) {
        let val = {
          objList: res.result.itemGroupVos,
          result: res.result.dmsShoppingTotalVo
        }
        this.dataUpdata(val)
      }
    },
    // 获取资金余额
    async getBalance(customerCode) {
      let res = await postAction(window._CONFIG['domianDmsURL'] + '/shopping/dmsShoppingHead/findAvailableBalance', {
        customerCode,
        payerCode: this.form.getFieldValue('payerCode')
      })
      if (res.success) {
        this.balance = res.result
      }
    },

    // 弹窗选择
    async okbropro(val, status, status2) {
      let objs = JSON.parse(JSON.stringify(val[0]))
      if (status == 'custCode') {
        this.form.resetFields()
        // 查询客户信息
        let res = await getAction(this.url.custInfoByCode, { customerCode: objs.custCode })
        if (res.success) {
          let params = {
            customerCode: res.result.custCode,
            customerName: res.result.custName,
            logisticsPatternCode: '2',
          }
          this.form.setFieldsValue({
            custCode: res.result.custCode,
            custName: res.result.custName,
            cooperationWayCode: res.result.cooperationWayCode,
          })
          // this.getPayer(res.result.custCode)
          this.getBalance(res.result.custCode)
          //获取客户提货点
          let val1 = await getAction(this.url.pickspot, { customerCode: res.result.custCode })
          if (val1.success) {
            let list = []
            if (val1.result.isTranMerc) {
              list = [{
                code: val1.result.pickUpPoint.transportCustomerCode,
                name: val1.result.pickUpPoint.transportCustomerName
              }]
            } else {
              list = val1.result.pickUpPoint.filter(v => (v.name && v.code))
            }
            if (list.length) {
              this.form.setFieldsValue({
                pupCode: list[0].code,
                pupName: list[0].name,
              })
              params.pupName = list[0].name
              params.pupCode = list[0].code
            }
            this.pupList = list
          } else {
            this.$message.error(val1.message)
          }
          // 生成/更新 表头
          let val = await postAction(this.url.addHead, params)
          if (val.success) {
            this.bottomInfo = val.result.dmsShoppingTotalVo
            this.$set(this, 'dataList', val.result.itemGroupVos || [])
            this.model = val.result
          } else {
            this.$message.error(val.message)
          }
        }
        let address = await postAction(this.url.addressUrl, { customerCode: this.form.getFieldValue('custCode') })
        if (address.success && address.result.records.length > 0) {
          this.form.setFieldsValue({
            addressCode: address.result.records[0].receivingAddressCode,
            addressDetailed: address.result.records[0].addressDetailed,
            addressRegion: address.result.records[0].receivedGoodsArea,
            consignee: address.result.records[0].receivedGoodsName,
            consigneeCall: address.result.records[0].receivedGoodsTel
          })
        }
      } else if (status == 'addressCode') {
        this.form.setFieldsValue({
          addressCode: objs.receivingAddressCode,
          addressDetailed: objs.addressDetailed,
          addressRegion: objs.receivedGoodsArea,
          consignee: objs.receivedGoodsName,
          consigneeCall: objs.receivedGoodsTel
        })
      } else if (status == 'gpCustCode') {
        this.form.setFieldsValue({
          gpCustCode: objs.finalCustomerCode,
          gpCustName: objs.contacts,
        })
        this.updateHead()
      }
    },
    // 获取付款方
    // async getPayer(customerCode) {
    //   let res = await getAction(this.url.payer, { customerCode })
    //   if (res.success) {
    //     this.payerList = res.objList || []
    //   }
    // },
    handleSelectProduct(e) {
      this.form.setFieldsValue({ 'productName': e[0].productName })
    },
    handleSelectCode() {
      this.$refs.CodeConfigModal.showModal(4)
    },
    add() {
      this.edit({}, 'add')
    },
    async edit(record, mark = 'edit') {

      if (mark == 'detail') {
        this.dataUpdata()
        this.visible = true
        this.confirmLoading = true
        this.id=record.id
        console.log(record)
        const res = await postAction(this.url.detail, { id: record.id })
        if (res && res.result) {
          record = res.result
        }
        this.confirmLoading = false
      }
      if (mark == 'edit') {
        this.visible = true
        this.confirmLoading = true
        this.id=record.id
        const res = await postAction(this.url.editDetail, { id: record.id })
        if (res.success) {
          if (res.result) {
            record = res.result
          }
        } else {
          this.$message.error(res.message)
        }
        this.confirmLoading = false
      }
      this.form.resetFields()
      if (record.id) {
        let list = record.itemGroupVos || []
        this.dataSource = this.model.actTermVos || []
        this.dataList = list.map(item => {
          item.show = false
          return item
        })
        this.bottomInfo = record.dmsShoppingTotalVo || {}
        delete record.itemGroupVos
        delete record.dmsShoppingTotalVo
        if (record.customerCode) {
          let res = await getAction(this.url.custInfoByCode, { customerCode: record.customerCode })
          if (res.success) {
            this.form.setFieldsValue({
              cooperationWayCode: res.result.cooperationWayCode,
            })
            let val1 = await getAction(this.url.pickspot, { customerCode: res.result.custCode })
            if (val1.success) {
              let list = []
              if (val1.result.isTranMerc) {
                list = [{
                  code: val1.result.pickUpPoint.transportCustomerCode,
                  name: val1.result.pickUpPoint.transportCustomerName
                }]
              } else {
                list = val1.result.pickUpPoint.filter(v => (v.name && v.code))
              }
              this.pupList = list
            } else {
              this.$message.error(val1.message)
            }
          }
        }
      }
      this.model = Object.assign({}, record)
      this.form.setFieldsValue({
        custName:this.model.customerName,
        custCode:this.model.customerCode,
      })
      console.log(this.form.setFieldsValue)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, Object.keys(this.model)))
        this.findProductByStockList()
        // mark != 'detail'&&record.orderType=='ZO10'&&this.findShoppingMatchingModels()
      })
    },
    handleadd(state){
      console.log(this.model)
      let oaVo={
        orderStatus:state,
        id:this.id
      }
      let that=this
      that.confirmLoading = true
      getAction(this.url.adddata, oaVo).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
          that.close()
        } else {
          that.$message.warning(res.message)
        }
      }).finally(() => {
        that.confirmLoading = false
        this.saveButtons = false
      })
    },
    // 选择本品
    async selectGoodsBp(rows) {
      if (rows) {
        let {
          detail
        } = this
        let params = {
          id: this.model.id,
          itemChangeEntityList: rows.map(detail => {
            return {
              productCode: detail.productCode || detail.goodsCode,
              productName: detail.productName,
              goodsCode: detail.goodsCode || detail.productCode,
              goodsName: detail.goodsName,
              originalPrice: detail.originalPrice,
              dataType: '1',
              quantity: detail.quantity||1
            }
          })
        }
        this.confirmLoading = true
        let res = await postAction(this.url.addCart, params)
        if (res.success) {
          this.dataUpdata(res)
        } else {
          this.$message.error(res.message)
        }
        this.confirmLoading = false
      }
    },
    // 删除
    async deleteRow(id, indexs, bpIndex) {
      let res = await postAction(this.url.delShopping, {
        id: this.model.id,
        itemIds: id
      })
      if (res.success) {
        this.$message.success('删除成功')
        this.dataUpdata(res)
      }
    },

    updateHB(res) {
      console.log(res)
      this.dataUpdata(res)
    },

    // 购物车更新数量/政策
    async upDataCart(item, key = 'updata') {
      if (this.timer) {
        clearTimeout(this.timer)
      }
      this.timer = setTimeout(async () => {
        if(this.model.orderType!='ZO16'&& this.model.orderType!='ZO11'){
          item.quantity = item.quantity || 1
        }
        let params = {
          id: this.model.id,
          itemChangeEntityList: [item]
        }
        this.confirmLoading = true
        let res = await postAction(this.url.shoppingUpQuantity, params)
        if (res.success) {
          await this.dataUpdata(res)
          if (key == 'promotion') {
            await this.findProductByStockList()
          }
        } else {
          this.$message.error(res.message)
        }
        this.confirmLoading = false
      }, 300)

    },
    // 赠品数量修改
    async addPmZps(row, e) {
      if (this.timer) {
        clearTimeout(this.timer)
      }
      let _this = this
      this.timer = setTimeout(async () => {
        let select = row.shoppingHeadZps.concat(row.gitGoodsLis).filter(item => item.quantity && item.quantity > 0)
        select.forEach(item => {
          item.promotionCode = row.pmCode
          item.originalPrice = item.originalPrice
        })
        let params = {
          id: _this.model.id,
          itemChangeEntityList: select,
          promotionCode: row.pmCode
        }
        _this.confirmLoading = true
        let res = await postAction(_this.url.addDZShopping, params)
        if (res.success) {
          await _this.dataUpdata(res)
        } else {
          _this.$message.error(res.message)
        }
        _this.confirmLoading = false
      }, 300)
    },
    async findProductByStockList() {
      if (this.form.getFieldValue('cooperationWayCode') == 2 || this.disableSubmit) {
        return
      }
      let pupCode = this.form.getFieldValue('pupCode')
      // debugger
      if (pupCode) {
        let {
          dataList
        } = this
        let productCodeList = []
        dataList.forEach(item => {
          productCodeList = [...productCodeList, ...item.shoppingHeads.map(val => val
            .productCode), ...item.shoppingHeadZps.map(val => val.productCode), ...item
            .gitGoodsLis.map(val => val.productCode)
          ]
        })
        productCodeList = Array.from(new Set(productCodeList))
        let res = await postAction(this.url.stock, {
          pupCode,
          productCodeList,
          // id: this.model.id,
          customerCode: this.form.getFieldValue('custCode')
        })
        if (res.success) {
          let stockList = {}
          res.objList.forEach(item => {
            stockList[item.productCode] = {
              stock: item.stock,
              oldStock: JSON.parse(JSON.stringify(item.stock))
            }
          })
          this.stockList = stockList
          this.dataList.forEach(item => {
            item.shoppingHeads = item.shoppingHeads.map(val => {
              return Object.assign({}, val, {
                stock: stockList[val.productCode] ? stockList[val.productCode].stock : 0,
                oldStock: stockList[val.productCode] ? stockList[val.productCode].oldStock : 0
              })
            })
            item.shoppingHeadZps = item.shoppingHeadZps.map(val => {
              return Object.assign({}, val, {
                stock: stockList[val.productCode] ? stockList[val.productCode].stock : 0,
                oldStock: stockList[val.productCode] ? stockList[val.productCode].oldStock : 0
              })
            })
            item.gitGoodsLis = item.gitGoodsLis.map(val => {
              return Object.assign({}, val, {
                stock: stockList[val.productCode] ? stockList[val.productCode].stock : 0,
                oldStock: stockList[val.productCode] ? stockList[val.productCode].oldStock : 0
              })
            })
          })
        }
      }
    },

    // 更新购物车
    dataUpdata(res) {
      let {
        dataList
      } = this
      if(res){
      res.objList.map(item => {
        item.show = false
        let index = dataList.findIndex(v => v.pmCode == item.pmCode)
        if (index != -1) {
          if (item.shoppingHeads.length) {
            dataList.splice(index, 1, item)
          } else {
            dataList.splice(index, 1)
          }
        } else {
          dataList.push(item)
        }
      })
      this.$set(this, 'dataList', dataList)
      this.bottomInfo = res.result
      // this.findShoppingMatchingModels()
      this.findProductByStockList()
      }
    },

    // 车型匹配
    // async findShoppingMatchingModels() {
    //
    //   let params = {
    //     id: this.model.id,
    //     logisticsPatternCode: this.form.getFieldValue('logisticsPatternCode'),
    //     pupCode: this.form.getFieldValue('pupCode'),
    //     carpoolingCode: this.form.getFieldValue('carpoolingCode'),
    //     customerCode: this.form.getFieldValue('customerCode')
    //   }
    //   let res = await postAction(this.url.match, params)
    //   if (res.success) {
    //     this.model.optimumMatchModel = res.result.optimumMatchModel
    //     this.model.optimumModelCode = res.result.optimumModelCode
    //     this.model.matchingModelsMsg = res.result.matchingModelsMsg
    //   } else {
    //     this.model.optimumMatchModel = '未查询到匹配车型'
    //     this.model.optimumModelCode = ''
    //     this.model.matchingModelsMsg = '未查询到匹配车型'
    //   }
    // },

    handleAdd() {
      this.modelname = '选择产品'
      this.searclist = this.searchConfig
      this.$refs.shuttleModal.visible = true
      this.$refs.shuttleModal.isorter.customerCode = this.form.getFieldValue('customerCode')
    },
    handleAdd1() {
      this.modelname = '收藏商品'
      this.searclist = this.searchConfig1
      this.columnslist = this.columnsModal1
      this.columnslist = this.columnsModal21
      this.url.goodsList = '/favorites/cnFavorites/findPageList'
      this.$refs.shuttleModal.visible = true
      this.$refs.shuttleModal.isorter = { customerCode: this.form.getFieldValue('custCode') }

      this.$refs.shuttleModal.searchReset()
    },
    handleAdd2() {
      this.modelname = '常购清单'
      this.searclist = this.searchConfig2
      this.columnslist = this.columnsModal21
      this.columnslist = this.columnsModal22
      this.$refs.shuttleModal.visible = true
    },
    close() {
      this.$emit('close')
      this.dataSource = []
      this.dataList = [] // 商品信息
      this.bottomInfo = {} // 结算信息
      this.pupList = [] // 提货点
      this.visible = false
    },
    handleOk1() {
      this.visible1 = false
    },
    showModal() {
      this.visible1 = true
    },
    handleOk(key) {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          let shoppingIds = []
          for (let item of this.dataList) {
            let bps = item.shoppingHeads.map(v => v.id)
            let zps = item.shoppingHeadZps.map(v => v.id)
            shoppingIds = [...shoppingIds, ...bps, ...zps]
          }
          let formData = Object.assign(this.model, values, { shoppingIds })
          formData.logisticsPatternName = formData.logisticsPatternCode == '1' ? '速冻' : '常温'
          //时间格式化
          that.confirmLoading = true
          let url = this.url.add
          if (key == 'zc') {
            url = this.url.edit
          }
          console.log(formData)
          postAction(url, formData).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    },
    handleCancel() {
      this.close()
      this.showterm = false
    },
    changeTerm(val) {
      if (val != undefined) {
        if (val === '' || val === '0') {
          this.showterm = false
          this.showorg = true
        } else {
          this.showterm = true
          this.showorg = false
        }
      }
    },

    custSearch(status) {
      this.modelname = '客户'
      // console.log('数据',status)
      this.$refs.prochoose.rowKey = 'custCode'
      let formconfig = [
        {
          key: 'custCode',
          label: '客户编号'
        },
        {
          key: 'custName',
          label: '客户名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '客户编号',
            align: 'center',
            dataIndex: 'custCode',
            width: 120,
            ellipsis: true
          },
          {
            title: '客户名称',
            align: 'center',
            dataIndex: 'custName',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/customerController/findPageList',
        multiple: false,
        jurisdiction: 'order_page_impl_add_cust',
        columW: 8
      }

      let dataSource = []
      if (this.form.getFieldValue('customerCode')) {
        dataSource = [{
          customerCode: this.form.getFieldValue('customerCode'),
          customerName: this.form.getFieldValue('customerName')
        }]
      }
      this.name = '客户'
      this.$refs.prochoose.isorter = { status: 1 }
      this.$refs.prochoose.edit(formconfig, tableconfig, status, 'customerName', dataSource)
    },

    custSearch0(status) {
      this.modelname = '收货地址'
      // console.log('数据',status)
      this.$refs.prochoose.rowKey = 'receivingAddressCode'
      let formconfig = [
        {
          key: 'receivingAddressCode',
          label: '收货地址编号'
        },
        {
          key: 'addressDetailed',
          label: '收货地址名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '收货地址编号',
            align: 'center',
            dataIndex: 'receivingAddressCode',
            width: 120,
            ellipsis: true
          },
          {
            title: '收货地址名称',
            align: 'center',
            dataIndex: 'addressDetailed',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/receivedgoodsaddress/cnReceivedGoodsAddress/findPageList',
        multiple: false,
        columW: 8
      }

      let dataSource = []
      if (this.form.getFieldValue('superiorUser')) {
        dataSource = [{
          receivingAddressCode: this.form.getFieldValue('addressCode'),
          addressDetailed: this.form.getFieldValue('addressDetailed')
        }]
      }
      this.name = '客户'
      this.$refs.prochoose.isorter = { status: 1, customerCode: this.form.getFieldValue('customerCode'), }
      this.$refs.prochoose.edit(formconfig, tableconfig, status, 'addressDetailed', dataSource)
    },

    gpCustSearch(status) {
      this.modelname = '团购客户'
      this.$refs.prochoose.rowKey = 'finalCustomerCode'
      let formconfig = [
        {
          key: 'finalCustomerCode',
          label: '团购客户编号'
        },
        {
          key: 'contacts',
          label: '团购客户名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '团购客户编号',
            align: 'center',
            dataIndex: 'finalCustomerCode',
            width: 120,
            ellipsis: true
          },
          {
            title: '团购客户名称',
            align: 'center',
            dataIndex: 'contacts',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/customer/cnPurchaseCustomer/findPageList',
        multiple: false,
        columW: 8
      }
      let dataSource = []
      if (this.form.getFieldValue('gpCustCode')) {
        dataSource = [{
          finalCustomerCode: this.form.getFieldValue('gpCustCode'),
          contacts: this.form.getFieldValue('gpCustName')
        }]
      }
      this.name = '客户'
      this.$refs.prochoose.isorter = { status: 1, customerCode: this.form.getFieldValue('customerCode'), }
      this.$refs.prochoose.edit(formconfig, tableconfig, status, 'contacts', dataSource)
    },

    custSearch01(status) {
      this.modelname = '提货点'
      // console.log('数据',status)
      this.$refs.prochoose.rowKey = 'pupCode'
      let formconfig = [
        {
          key: 'pupCode',
          label: '提货点编号'
        },
        {
          key: 'pupName',
          label: '提货点名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '提货点编号',
            align: 'center',
            dataIndex: 'pupCode',
            width: 120,
            ellipsis: true
          },
          {
            title: '提货点名称',
            align: 'center',
            dataIndex: 'pupName',
            width: 120,
            ellipsis: true
          }
        ],
        list: window._CONFIG['domianURL'] + '/pupconfig/cnPupConfig/findPageList',
        multiple: false,
        columW: 8
      }

      let dataSource = []
      if (this.form.getFieldValue('superiorUser')) {
        dataSource = [{
          pupCode: this.form.getFieldValue('superiorUser'),
          pupName: this.form.getFieldValue('realName')
        }]
      }
      this.name = '客户'
      this.$refs.prochoose.isorter = { status: 1 }
      this.$refs.prochoose.edit(formconfig, tableconfig, 'superiorUser', 'realsname', dataSource)
    },
    custSearch1() {
      this.$refs.orderspModal.isorter = {
        status: 1,
        custCode: this.form.getFieldValue('custCode')
      }
      let item = this.dataList.find(item => item.pmCode == 'hbzp')
      let select = []
      if (item) {
        select = item.shoppingHeads.filter(val => val.dataType == '2')
      }
      this.modelname = '添加货补商品'
      // console.log('数据',status)
      this.$refs.orderspModal.rowKey = 'id'
      let formconfig = {
        id: this.model.id,
        select
      }
      let tableconfig = {
        columns: [
          {
            title: '产品组编号',
            align: 'center',
            dataIndex: 'classifyCode',
            ellipsis: true
          },
          {
            title: '产品组名称',
            align: 'center',
            dataIndex: 'classifyName',
            ellipsis: true
          },
          {
            title: '商品编号',
            align: 'center',
            dataIndex: 'goodsCode',
            ellipsis: true
          },
          {
            title: '商品名称',
            align: 'center',
            dataIndex: 'goodsName',
            ellipsis: true
          },
          {
            title: '可用余额（元）',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          },
          {
            title: '数量',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          },
          {
            title: '合计',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          }
        ],
        list:window._CONFIG['domianURL'] +  '/fee/cnFeeManage/findPageListByOrgOrCustomer',
        multiple: false,
        columW: 8,
        custCode:this.form.getFieldValue('custCode'),
      }
      let dataSource = []
      if (this.form.getFieldValue('superiorUser')) {
        dataSource = [{
          userName: this.form.getFieldValue('superiorUser'),
          realName: this.form.getFieldValue('realName')
        }]
      }
      this.$refs.orderspModal.edit(formconfig, tableconfig, 'superiorUser', 'realsname', dataSource)
    },
    custSearch2(status) {
      this.modelname = '添加赠品'
      // console.log('数据',status)
      this.$refs.orderspModal.rowKey = 'id'
      let formconfig = [
        {
          key: '',
          label: '产品组名称'
        },
        {
          key: '',
          label: '赠品编号'
        },
        {
          key: '',
          label: '赠品名称'
        }
      ]
      let tableconfig = {
        columns: [
          {
            title: '产品组编号',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          },
          {
            title: '产品组名称',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          },
          {
            title: '赠品编号',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          },
          {
            title: '赠品名称',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          },
          {
            title: '可用余额（元）',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          },
          {
            title: '数量',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          },
          {
            title: '合计',
            align: 'center',
            dataIndex: '',
            ellipsis: true
          }
        ],
        list: '',
        multiple: false,
        columW: 8
      }

      let dataSource = []
      if (this.form.getFieldValue('superiorUser')) {
        dataSource = [{
          userName: this.form.getFieldValue('superiorUser'),
          realName: this.form.getFieldValue('realName')
        }]
      }
      this.$refs.orderspModal.edit(formconfig, tableconfig, 'superiorUser', 'realsname', dataSource)
    },

    handleSelectTerm(list) {
      this.dataSource = list
    },
    handleDelete(index) {
      this.dataSource.splice(index, 1)
    },
    beforeUpload(file) {
      this.handleReadExcel(file)
      return false
    },
    handleReadExcel(file) {
      const that = this
      const fileReader = new FileReader()
      fileReader.onload = ev => {
        try {
          const fileData = ev.target.result
          const workbook = XLSX.read(fileData, {
            type: 'binary'
          })
          const wsname = workbook.SheetNames[0] // 取第一张表
          const snArr = XLSX.utils.sheet_to_json(workbook.Sheets[wsname]) // 生成json表格内容
          console.log(snArr) // 读取到的SN列表
          debugger
          // 遍历SN放入Set集合 snSet
          let list = snArr.map(item => Object.assign({
            productCode: item['* 商品编码'],
            quantity: item['* 数量'],
          }))
          list = list.filter(item => item.productCode && item.quantity)
          if(list.length){
            that.selectGoodsBp(list)
          }else {
            this.$message.warning('未解析到数据，请按模版添加！')
          }
        } catch (e) {
          return false
        }
      }
      fileReader.readAsBinaryString(file)
      console.log(fileReader)
    },
    handleExportXls(fileName) {
      if (!fileName || typeof fileName != 'string') {
        fileName = '导出文件'
      }
      let param = { ...this.queryParam }
      if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
        param['selections'] = this.selectedRowKeys.join(',')
      }
      console.log('导出参数', param)
      downFile(this.url.exportXlsUrl, param).then((data) => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', fileName + '.xls')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
  }
}
</script>

<style lang="less" scoped>
/deep/ .ant-modal-body {
  padding-top: 0 !important;
}

.ant-calendar-picker, .ant-input-number {
  width: 100% !important;
}

/* table */
.table-box {
  overflow-x: scroll;
  background-color: #ffffff;
  /* width: 1100px; */
  /* height: 100px; */

  .table-checkbox {
    width: 50px !important;
    min-width: 50px !important;
    flex: none !important;
  }

  .table-head-box {
    display: flex;
    //min-width: 1173px;
    /* display: flex; */
    font-size: 0;

    .table-head-th {
      min-width: 80px;
      min-height: 40px;
      display: flex;
      background-color: #fff;
      justify-content: center;
      align-items: center;
      text-align: center;
      box-sizing: border-box;
      font-size: 14px;
      font-weight: 600;
      border-right: 1px solid #FFF;
      margin: 0;
      flex-shrink: 0;
    }
  }


  .table-body-box {
    display: flex;
    //min-width: 1173px;
    font-size: 14px;

    &:hover {
      .table-body-td {
        //background-color: #FDEFEC;
      }
    }

    .table-body-td {
      box-sizing: border-box;
      display: flex;
      justify-content: center;
      align-items: center;
      margin: auto;
      font-weight: 500;
      /* border: 1px solid #eee; */
      min-width: 80px;
      font-size: 14px;
      margin: 0;
      padding: 4px 5px;
      min-height: 40px;
      flex-shrink: 0;
    }
  }

  .table-body-box-zp {
    position: relative;
    min-width: 1350px;

    .td-zl {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      right: 20px;
    }

    .td-zpkxsl {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      left: 1000px;
      width: 150px !important;
      flex: none !important;
    }

    .table-body-td {
      background-color: #ebebeb;
    }

  }

  .arrow-down {
    transform: rotate(-90deg);
  }

  .arrow-up {
    transform: rotate(90deg);
  }
}

.bg-ebebeb {
  background-color: #ebebeb;
}

.td-spbm {
  width: 100px !important;
  flex: none !important;
}

.td-spmc {
  width: 280px !important;
  flex: none !important;
}

.td-hlx {
  width: 124px !important;
  flex: none !important;
}

.td-dw {
  width: 50px !important;
  min-width: 50px !important;
  flex: none !important;
}

.td-jsje {
  width: 100px !important;
  flex: none !important;
}

.td-zc {
  width: 180px !important;
  flex: none !important;
}

.td-zpkxsl {
  width: 150px !important;
  flex: none !important;
}

.td-ysds, .td-ysjs, .td-sl {
  width: 90px !important;
  flex: none !important;
}
</style>